#include "common.h"

void bit_to_word( vector<bit> bit_vector , word val[] , const int array_num )
{
	for ( int i = 0 ; i < array_num ; ++i )
	{
		val[i] = 0 ;
		vector<bit>::size_type begin_index = i * (bit_vector.size()/array_num) ;
		vector<bit>::size_type end_index = (i+1) * (bit_vector.size()/array_num) ;
		for ( ; begin_index < end_index ; ++begin_index )
		{
			val[i] = (bit_vector[begin_index]<<((i+1)*(bit_vector.size()/array_num) - begin_index - 1))|val[i] ;
		}
	}
}

void bit_to_nibble( vector<bit> bit_vector , nibble val[] , const int array_num )
{
	for ( int i = 0 ; i < array_num ; ++i )
	{
		val[i] = 0 ;
		vector<bit>::size_type begin_index = i * (bit_vector.size()/array_num) ;
		vector<bit>::size_type end_index = (i+1) * (bit_vector.size()/array_num) ;
		for ( ; begin_index < end_index ; ++begin_index )
		{
			val[i] = (bit_vector[begin_index]<<((i+1)*(bit_vector.size()/array_num) - begin_index - 1))|val[i] ;
		}
	}
}

void nibble_to_bit( nibble val[] , const int array_num , vector<bit>& bit_vector )
{
	for ( int i = 0 ; i < array_num ; ++i )
	{
		for ( int j = 3 ; j >= 0 ; --j )
		{
			bit temp = (val[i]>>j) & 0x01 ;
			bit_vector.push_back( temp ) ;
		}
		 
	}
}